//
//  FriendViewController.m
//  TouTiao
//
//  Created by 柴旭 on 16/9/12.
//  Copyright © 2016年 Match. All rights reserved.
//

#import "FriendViewController.h"
#import "SearchViewController.h"
#import "FriendsTableViewCell.h"
#import "UIBarButtonItem+buttonItem.h"
#import <MJRefresh.h>
#import "DynamicViewController.h"
@interface FriendViewController ()<UITableViewDataSource,UITableViewDelegate>


@end

@implementation FriendViewController



#pragma mark viewDidLoad
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.frame = self.view.bounds;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    //创建下拉刷新
    MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self performSelector:@selector(headerRefresh) withObject:nil afterDelay:0.2];
    }];
    //设置自定义文字，默认为英文
    [header setTitle:@"下拉刷新" forState:MJRefreshStateIdle];
    [header setTitle:@"松开加载更多" forState:MJRefreshStatePulling];
    [header setTitle:@"正在刷新" forState:MJRefreshStateRefreshing];
    self.tableView.mj_header = header;
    
    
    [self addItem];//添加右边的按钮

}

#pragma mark 刷新的单击事件
-(void)headerRefresh{
    NSLog(@"下拉，加载数据");
    [self.tableView.mj_header endRefreshing];
}

#pragma mark 添加右边的按钮
-(void)addItem{
    UIBarButtonItem *itemL = [UIBarButtonItem barButtonItemWith:[UIButton buttonWithType:UIButtonTypeCustom] addTarget:self action:@selector(rightClick) andImage:@"addicon_titlebar_topic_night" andHighlighted:@"addicon_titlebar_topic"];
    self.navigationItem.rightBarButtonItem=itemL;
    
    self.navigationItem.title=@"我关注的";
}

#pragma mark 右边按钮的单击事件
-(void)rightClick{
    SearchViewController *search=[[SearchViewController alloc] init];
    search.hidesBottomBarWhenPushed = YES;
    //进入搜索关注界面
    [self.navigationController pushViewController:search animated:YES];
}



#pragma mark 组数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

#pragma mark 设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 1) {
        return 8;
    }
    return 1;
}

#pragma mark 定义单元格cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        static NSString * ID = @"cell";
        FriendsTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
        if (cell == nil) {
            cell = [FriendsTableViewCell loadTableViewcell];
        }

        return  cell;
        
    }else{
        
        static NSString *ID = @"accept";

        UITableViewCell *temp = [tableView dequeueReusableCellWithIdentifier:ID];
        if (temp == nil) {
            temp = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        }
        return temp;
        
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

#pragma mark 点击好友动态cell进入动态界面
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        DynamicViewController *dynamic = [[DynamicViewController alloc] init];
        [self.navigationController pushViewController:dynamic animated:YES];
      
//        [self.tableView.mj_header beginRefreshing];
        
    }else{
        
    }

}


@end
